package com.example.java.newFeature;

public class TextBlocksDemo {
    public static void main(String[] args) {
        // 传统的字符串拼接方式
        String traditionalString = "This is a long string\n" +
                "that spans multiple lines.\n" +
                "You need to use concatenation\n" +
                "or escape characters to format it.";

        System.out.println(traditionalString);


        System.out.println("----------------------------------------------------------");

        // 使用文本块(text block) 简化多行字符串（如 JSON、SQL、HTML）。
        // 在Java中引入的文本块（Text Blocks）功能确实简化了多行字符串的处理。文本块使用三个双引号 """ 作为开始和结束定界符，使得编写多行字符串变得更加直观和简洁。
        String textBlock = """
                This is a long string
                that spans multiple lines.
                You need to use concatenation
                or escape characters to format it.
                """;

        System.out.println(textBlock);

        String json = """
                {
                    "name": "Java",
                    "version": 21
                }
                """;
        System.out.println(json);
    }
}
